package color;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * 图片面板
 */

public class ImageJPanel extends JPanel {
    private static final long serialVersionUID = 1L;
    private BufferedImage sourceImage;
    //调整后图片
    private BufferedImage destImage;
    /**
     * 构造方法
     */
    public ImageJPanel(){}

    /**
     * 获取原图
     * @return sourceImage 原图
     */
    public BufferedImage getSourceImage() {
        return sourceImage;

    }

    /**
     * 设置原图
     * @param sourceImage 原图
     */
    public void setSourceImage(BufferedImage sourceImage) {
        this.sourceImage = sourceImage;

    }

    /**
     * 获取调整后图片
     * @return deskImage 调整后图片
     */
    public BufferedImage getDestImage() {
        return destImage;

    }

    /**
     * 设置调整后图片
     * @param destImage 调整后图片
     */
    public void setDestImage(BufferedImage destImage) {
        this.destImage = destImage;

    }

    /**
     * 创建deskImage
     * @param src 原图参数
     */

    public void process(double src[]){
        double s = 0.0,b = 0.0,c = 0.0;
        AdjustFilter Filter = new AdjustFilter();
        //设置亮度
        Filter.setSaturation(src[0]);
        //设置对比度
        Filter.setBrightness(src[1]);
        //设置饱和度
        Filter.setContrast(src[2]);
        //赋给deskImage
        destImage = Filter.filter(sourceImage,null);

    }

    /**
     *绘制原图以及调整后图片 设置位置
     * @param g 图形
     */
    public void paintComponent(Graphics g){
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.clearRect(0,0,this.getWidth(),this.getHeight());
        //获取屏幕大小
        Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
        //全屏
        double x1=screenSize.width*0.1;
        double y=screenSize.height*0.2;
        int X1=(int)x1;
        int Y=(int)y;
        double x2=screenSize.width*0.6;
        int X2=(int)x2;
        setSize(screenSize.width,screenSize.height-10);
        //如果sourceImage以及创建
        if(sourceImage != null){
            g2d.drawImage(sourceImage,X1,Y,sourceImage.getWidth(),sourceImage.getHeight(),null);
            //如果deskImage以及创建
            if(destImage != null){
                g2d.drawImage(destImage,X2,Y,destImage.getWidth(),destImage.getHeight(),null);
            }
        }
    }
}
